package org.example;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        ListNode a = new ListNode(2); head.next = a;
        ListNode b = new ListNode(3); a.next = b;
        ListNode c = new ListNode(4); b.next = c;
        ListNode d = new ListNode(5); c.next = d;
        d.next = null;
        int k = 2;
        ListNode Fast = head;
        ListNode Slow = head;
        while (k != 0) {
            Fast = Fast.next;
            k--;
        }
        while (Fast != null) {
            Fast = Fast.next;
            Slow = Slow.next;
        }
        System.out.println("Slow: " + Slow.val);
    }
    public static void main4(String[] args) {
        ListNode head = new ListNode(1);
        ListNode a = new ListNode(2); head.next = a;
        ListNode b = new ListNode(3); a.next = b;
        ListNode c = new ListNode(4); b.next = c;
        ListNode d = new ListNode(5); c.next = d;
        d.next = null;
        ListNode Fast = head;
        ListNode Slow = null;
        ListNode temp = null;
        while (Fast != null) {
            temp = Fast.next;
            Fast.next = Slow;
            Slow = Fast;
            Fast = temp;
        }
    }
    public static void main3(String[] args) {
        int val = 3;
        ListNode head = new ListNode(1);
        ListNode a = new ListNode(2); head.next = a;
        ListNode b = new ListNode(3); a.next = b;
        ListNode c = new ListNode(4); b.next = c;
        ListNode d = new ListNode(5); c.next = d;
        d.next = null;
        if(head == null){
            return ;
        }
        ListNode cur1 = head;
        ListNode cur2 = head;
        while(head != null && head.val == val){
            head = head.next;
        }
        cur1 = cur1.next;
        while (cur1 != null) {
            if(cur1.val == val){
                cur2.next = cur1.next;
            }else{
                cur2 = cur2.next;
            }
            cur1 = cur1.next;
        }
        System.out.println(cur2.val);


    }
    public static void main2(String[] args) {
        ListNode head = new ListNode(1);
        ListNode a = new ListNode(2); head.next = a;
        ListNode b = new ListNode(3); a.next = b;
        ListNode c = new ListNode(4); b.next = c;
        ListNode d = new ListNode(5); c.next = d;
        d.next = null;
        ListNode Fast = head;
        ListNode Slow = head;
        while (Fast != null && Fast.next != null) {
            Fast = Fast.next;
            Fast = Fast.next;
            Slow = Slow.next;
        }
        System.out.println(Slow.val);
    }
    public static void main1(String[] args) {
        int numRows = 5;
        List<List<Integer>> lists = new ArrayList<List<Integer>>();
        for (int i = 0; i < numRows; i++) {
            List<Integer> row = new ArrayList<Integer>();
            for (int j = 0; j <= i; j++) {
                if(j == 0 || i == j){
                    row.add(1);
                }else {
                    row.add(lists.get(i - 1).get(j - 1)
                    + lists.get(i - 1).get(j));
                }
            }
            lists.add(row);
        }
        System.out.println(lists);
    }
}